const colors = ['#43c4a4', '#f7917d', '#251314']

var degrees = [...Array(360).keys()]

const asyncData = {
  "relations": [
    {
        "distance": 1,
        "authors": [
            {
                "authorId": 8573,
                "name": "David Robert Martin Thompson"
            },
            {
                "authorId": 41980,
                "name": "Rebecca Castaño"
            },
            {
                "authorId": 68652,
                "name": "Benjamin J Bornstein"
            },
            {
                "authorId": 74611,
                "name": "Michael C Burl"
            },
            {
                "authorId": 104480,
                "name": "Michele  Judd"
            },
            {
                "authorId": 127311,
                "name": "Daniel M Gaines"
            },
            {
                "authorId": 137432,
                "name": "Robert C Anderson"
            }
        ]
    },
    {
        "distance": 2,
        "authors": [
            {
                "authorId": 8532,
                "name": "Francisco J Calderoon Peralta"
            },
            {
                "authorId": 15455,
                "name": "Michael  Furlong"
            },
            {
                "authorId": 16096,
                "name": "Damhnait  Gleeson"
            },
            {
                "authorId": 23127,
                "name": "Robert T Pappalardo"
            },
            {
                "authorId": 30117,
                "name": "Jeffrey Solomon Rosenschein"
            },
            {
                "authorId": 49827,
                "name": "Kevin Leyton-Brown"
            },
            {
                "authorId": 64220,
                "name": "Steve  Chien"
            },
            {
                "authorId": 68040,
                "name": "Greydon T Foil"
            },
            {
                "authorId": 85913,
                "name": "Anatha Ravi Kiran"
            },
            {
                "authorId": 96199,
                "name": "Omer  Lev"
            },
            {
                "authorId": 118995,
                "name": "Umaa Devi Rebbapragada"
            },
            {
                "authorId": 139076,
                "name": "Lukas  Mandrake"
            },
            {
                "authorId": 141600,
                "name": "David Strod Wettergreen"
            },
            {
                "authorId": 150197,
                "name": "Kiri Wagstaff"
            },
            {
                "authorId": 167157,
                "name": "Daniel  Tran"
            }
        ]
    },
    {
        "distance": 3,
        "authors": [
            {
                "authorId": 406,
                "name": "Zinovi  Rabinovich"
            },
            {
                "authorId": 6847,
                "name": "Roie  Zivan"
            },
            {
                "authorId": 7329,
                "name": "Holger Hoos"
            },
            {
                "authorId": 14390,
                "name": "Tal  Ze'evi"
            },
            {
                "authorId": 15396,
                "name": "Itay  Sabato"
            },
            {
                "authorId": 19642,
                "name": "Cynthia  Phillips"
            },
            {
                "authorId": 20349,
                "name": "Shaull  Almagor"
            },
            {
                "authorId": 21543,
                "name": "Aviv  Zohar"
            },
            {
                "authorId": 27413,
                "name": "Svetlana  Obraztsova"
            },
            {
                "authorId": 29905,
                "name": "George A Kantor"
            },
            {
                "authorId": 33793,
                "name": "Nir  Pochter"
            },
            {
                "authorId": 36260,
                "name": "Steven  Damer"
            },
            {
                "authorId": 40776,
                "name": "Peter Stone"
            },
            {
                "authorId": 43084,
                "name": "Colin M Creager"
            },
            {
                "authorId": 43262,
                "name": "James R Wright"
            }
        ]
    },
    {
        "distance": 4,
        "authors": [
            {
                "authorId": 157,
                "name": "Pushmeet  Kholi"
            },
            {
                "authorId": 764,
                "name": "Davide Grossi"
            },
            {
                "authorId": 1082,
                "name": "Esther  David"
            },
            {
                "authorId": 2061,
                "name": "Craig Boutilier"
            },
            {
                "authorId": 2303,
                "name": "Amos  Azaria"
            },
            {
                "authorId": 2647,
                "name": "Birna van Riemsdijk"
            },
            {
                "authorId": 3016,
                "name": "Avrim Louis Blum"
            },
            {
                "authorId": 3985,
                "name": "Makoto Yokoo"
            },
            {
                "authorId": 4245,
                "name": "Claudia V Goldman"
            },
            {
                "authorId": 4370,
                "name": "Chao  Zhang"
            },
            {
                "authorId": 4686,
                "name": "Thanh Hong Nguyen"
            },
            {
                "authorId": 4761,
                "name": "Joachim  Meyer"
            },
            {
                "authorId": 5064,
                "name": "Francisco  Barrera"
            },
            {
                "authorId": 5087,
                "name": "Tomoaki  Yoshida"
            },
            {
                "authorId": 5188,
                "name": "Kanleung  Cheng"
            }
        ]
    }
]
}

const authorName = 'Daniel Andre Vaquero';
const authorId = 10001;

// 需要添加name和data
const seriesSet = {
  type: 'scatter',
  label: {
    normal: {
      show: true,//显示
      formatter: function(params){
        return params.value[4];
      },
      position: 'bottom'
    }
  },
  coordinateSystem: 'polar',
  symbolSize: function (val) {
    return val[2] * 2;
  },
  itemStyle: {
    emphasis: {
      shadowBlur: 10,
      shadowColor: '#fff'
    }
  },
};

var days = new Array((asyncData.relations.length + 1) * 60).fill('');
days[0] = 'close';

const data_list = [[{
  value: [0, 0, 30, authorId, authorName],
  label: {
    color: '#000',
    position: 'inside'
  },
  itemStyle: {
    color: '#5ccef9'
  }
}]];

const relations = asyncData.relations;
relations.map((relation, i) => {
  const authors = relation.authors;
  // 基准
  const base = (i * 61 + 30) * 360;
  // 偏移量
  // const offset = 0;
  const offset = 360 * 50 / (authors.length);
  // console.log('authors', authors);
  data_list.push([]);
  authors.map((element, j) => {
    const x = parseInt(((base + j * offset) / 360).toFixed());
    const y = parseInt(((base + j * offset) % 360).toFixed()) - Math.round(Math.random() * offset % 360 / 4);
    data_list[i+1].push({value: [x, y,
      9 + Math.round(Math.random() * 4),
      element.authorId, element.name], 
    itemStyle: {
      color: colors[i]
    }})
  })
});

const name_list = ['Origin Author', 'Closed Authors', 'Not Too Close', 'Normal Close', 'Far Close'];
const series = data_list.map((value, index) => {
  const seriesItem = Object.assign({}, seriesSet);
  seriesItem.name = name_list[index];
  seriesItem.data = value;
  return seriesItem;
});



const option = {
    title: {
      text: 'Relations',
    },
    legend: {
      left: 'right',
  },
    polar: {radius: '96%'},
    tooltip: {
      formatter: function (params) {
        return params.data[4];
      }
    },
    angleAxis: {
      type: 'category',
      data: degrees,
      boundaryGap: false,
      axisLine: {
        show: false
      },
      axisLabel: {
        show: false
      },
      axisTick:{       //y轴刻度线
        "show":false
      },
    },
    radiusAxis: {
      type: 'category',
      data: days,
      // boundaryGap: false,
      axisLine: {
        show: false
      },
      splitLine: {
        show: true
      },
      markLine: {
        show: false
      },
      axisLabel: {
        show: false,
      },
      axisTick:{       //y轴刻度线
        "show":false
      },
    },
    series
};


var myChart = echarts.init(document.getElementById('main'));

myChart.setOption(option)

myChart.on('click', function (params) {
  // 在用户点击后控制台打印数据的名称
  console.log(params);
});